<?php
namespace App\Repositories;

use App\Exceptions\BasicException;
use Illuminate\Support\Facades\Hash;    //引入hash

class NobilityRepository
{
    /**
     * 获取爵位列表
     * @return list
     */
    public function NobilityList()
    {
        $list = app('model_nobility');
        $list = $list->get();
        return $list;
    }

    /**
     * 添加爵位
     * @param $param
     * @return bool
     * @throws BasicException
     */
    public function nobilityAdd($param=[])
    {
        $result = app('model_nobility')->create($param);
        if($result) {
            $this->delNobilityCache();
            return $result;
        }
        throw new BasicException(93013);
    }


    /**
     * 编辑爵位
     * @param $param
     * @return bool
     * @throws BasicException
     */
    public function nobilitySave($param=[])
    {
        $rankSave = app('model_nobility')->where('id',$param['id'])->update($param);
        if($rankSave!==false) {
            $this->delNobilityCache();
            return true;
        }
        throw new BasicException(93014);
    }


    /**
     * 删除爵位
     * @param $param
     * @return bool
     * @throws BasicException
     */
    public function nobilityDel($param=[])
    {
        $rankDel = app('model_nobility')->whereIn('id',$param)->delete();
        if($rankDel) {
            $this->delNobilityCache();
            return $rankDel;
        }
        throw new BasicException(93015);
    }

    private function delNobilityCache()
    {
        $key = 'nobility:config';
        app('redis')->del($key);
    }

    /**
     * 爵位详情
     * @param $id
     * @return bool
     * @throws BasicException
     */
    public function nobilityDetail($id)
    {
        $nobilityDetail = app('model_nobility')->where('id',$id)->first();
        if($nobilityDetail) return $nobilityDetail;
        throw new BasicException(50002);
    }







}


?>